package com.hbzhou.open.camera.slice;

import com.hbzhou.open.camera.ResourceTable;
import com.hbzhou.open.camera.util.ToastUtil;
import com.hbzhou.open.flowcamera.util.LogUtil;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;

/**
 * WelcomeAbilitySlice
 */
public class WelcomeAbilitySlice  extends AbilitySlice {
    private static final int SLICE_CODE = 0;
    private Button btnStartCamerax;

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_welcome);
        Component componentById = findComponentById(ResourceTable.Id_btn_start_camerax);
        if (componentById instanceof Button) {
            btnStartCamerax = (Button) componentById;
            btnStartCamerax.setClickedListener(component ->
                            presentForResult(new MainAbilitySlice(), new Intent(), SLICE_CODE));
        }
    }

    @Override
    protected void onActive() {
        super.onActive();
        //getWindow().setStatusBarVisibility(Component.INVISIBLE);
    }

    @Override
    protected void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    protected void onResult(int requestCode, Intent resultIntent) {
        super.onResult(requestCode, resultIntent);
        try {
            if (requestCode == SLICE_CODE && resultIntent != null) {
                if (resultIntent.hasParameter("PHOTO_URL")) {
                    String photoUrl = resultIntent.getStringParam("PHOTO_URL");
                    if (photoUrl == null || "".equals(photoUrl)) {
                        return;
                    }
                    LogUtil.info(LogUtil.DEFAULT_TAG, "onResult photoUrl:" + photoUrl);
                    ToastUtil.showToast(this, photoUrl);
                }
            }
        } catch (Exception vrp) {
            LogUtil.info(LogUtil.DEFAULT_TAG, "onResult error:" + vrp.getMessage());
        }
    }
}
